﻿<!--Files Operator version 0.6 -->

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="filetree6.aspx.cs" Inherits="FileTree6" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<title>FileTree</title>
	<script type="text/javascript" src="Scripts/jquery-1.4.2.min.js"></script>
	<script type="text/javascript" src="Scripts/Script.js"></script>
	<script type="text/javascript" src="Scripts/Serialize.js"></script>
	<script type="text/javascript" src="Scripts/tree.js"></script>
	<script type="text/javascript" src="Scripts/prototype-1.6.0.3-m.js"></script>
	<link href="filetree6.aspx.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript">
//<![CDATA[
		var url = '<%=Request.RawUrl%>';
		var imgBeforeExpandUrl = "images/BeforeExpand.gif";         //点击展开图标
		var imgExpandUrl = "images/expand.gif";         //点击展开图标
		var imgCollapseUrl = "images/collapse.gif";     //点击折叠图标
		var icoGroup = "images/group.gif";              //组图标
		var StatusBarDiv;
		var GroupNameHash = new Hash();
		var ObjectNameHash = new Hash();
		var ObjectIconHash = new Hash();
		var SubNodeHash = new Hash();
		var t = 10000, timer;  //自动刷新间隔
		var RootNode;
		var GroupListClass = "<%=GroupListClass%>";
		var ObjectListClass = "<%=ObjectListClass%>";
		var PageTitlesFloater, PageTitlesOuter, PageTitlesDoor;
		var Pages = new Hash();
		var CurentPageTitle, CurentPage;
		function getGroupsDivHtml(GroupID, Checked, GroupName)  //节点内容HTML
		{
			var CheckedString = "";
			if (Checked) CheckedString = " checked=\"checked\"";
			return "<div title=\"" + GroupID + "\" onclick=\"SetOperationFocus(this);\" oncontextmenu=\"SetOperationFocus(this);return Menu_1(event);\"><img class=\"ico\" src=\"" + imgBeforeExpandUrl + "\" alt=\"展开\" onclick=\"LoadNode(this);\" style=\"vertical-align: middle;\" /><img src=\"" + icoGroup + "\" style=\"vertical-align: middle;\" /><input id=\"GroupCheckbox|" + GroupID + "\" name=\"GroupCheckbox|" + GroupID + "\" type=\"checkbox\"" + CheckedString + " onclick=\"checkBox(this);\" style=\"vertical-align: middle;\" /><label><a >" + GroupName + "</a></label></div><div id=\"childDiv|" + GroupID + "\"></div>";
		}
		function getObjectsDivHtml(ID, Checked, Name, Icon) {
			var CheckedString = "";
			if (Checked) CheckedString = " checked=\"checked\"";
			ObjectNameHash.set(ID, Name);
			ObjectIconHash.set(ID, Icon);
			return "<div onclick=\"SetOperationFocus(this);\" oncontextmenu=\"SetOperationFocus(this);return Menu_1(event);\"><img src=\"" + Icon + "\" onerror=\"this.src='filetypeIcon/Unknown.gif'\" alt=\"\" onclick=\"\" style=\"vertical-align: middle;\" /><input id=\"ObjectCheckbox|" + ID + "\" name=\"ObjectCheckbox|" + ID + "\" type=\"checkbox\"" + CheckedString + " onclick=\"checkBox(this);\" style=\"vertical-align: middle;\" /><label><a href=\"" + ID + "\" target=\"_blank\">" + Name + "</a></label></div>";
		}
		function pageOnload() {
			StatusBarDiv = document.getElementById("StatusBar");
			RootNode = $("RootNode");
			//<%if ((UserEntry)Session["logined"] != null){%>
			RootNode.id = '<%=((UserEntry)Session["logined"]).UserRootPath%>';
			RootNode.innerHTML = getGroupsDivHtml(RootNode.id, false, RootNode.id);
			LoadNode(RootNode.firstChild.firstChild);
			//<%}%>
			PageTitlesDoor = $("PageTitlesDoor");
			PageTitlesOuter = $("PageTitlesOuter");
			PageTitlesFloater = $("PageTitlesFloater");
			CurentPageTitle = $("StartPageTitle");
			CurentPage = $("StartPage");
			Pages.set(CurentPageTitle.id, [CurentPageTitle, CurentPage]);
		}
		function getStatusIco(ObjectStatus) {
			return "filetypeIcon/" + ObjectStatus + ".gif";
			//  switch (ObjectStatus.toLowerCase())
			//	{
			//		case ".xml":
			//		    return "filetypeIcon/Xml.gif";
			//	}
		}
		function LoadNode(o, reload) {
			var LoadMessage = "展开" + o.parentNode.childNodes[3].firstChild.firstChild.data;
			var StartLoadTime_S, LoadedTime_S;
			if (typeof (reload) == 'undefined') reload = false;
			var ChildDiv = o.parentNode.nextSibling;
			var ZhedieIco = o.parentNode.firstChild;
			var id = ChildDiv.id.split('|')[1];
			var postbody = 'act=LoadNode&id=' + id;
			new Ajax.Request(url, {
				method: 'post',
				postBody: postbody,
				onFailure: reportError,
				onCreate: function () {
					StatusBarDiv.firstChild.data = "正在载入“" + id + "”……";
					ZhedieIco.onclick = null;
					ZhedieIco.nextSibling.ondblclick = null;
					ZhedieIco.src = "images/Loading10.gif";
					ZhedieIco.alt = "正在载入……";
					ZhedieIco.style.cursor = "wait";
					StartLoadTime_S = new Date().getTime();
				},
				onLoaded: function () {
					LoadedTime_S = new Date().getTime();
					var LoadedTime = LoadedTime_S - StartLoadTime_S;
					LoadMessage += "，传输用时：" + LoadedTime + " ms";
				},
				onSuccess: function (transport) { onSuccess(transport) },
				onComplete: function () { StatusBarDiv.firstChild.data = LoadMessage; }
			});
			function onSuccess(transport) {
				if (!reload) {
					SubNodeHash.set(id, [ChildDiv, new Hash()]);
					if (ChildDiv.parentNode == RootNode) {
						$("checkedbox").innerHTML = "<div>刷新时间：<input id=\"RefreshTime\" type=\"text\" size=\"6\" style=\"text-align:right;\" />秒<input id=\"SetTime\" type=\"button\" value=\"设置\" onclick=\"return SetTime_onclick(this);\" /></div>";
						$("RefreshTime").value = t / 1000;
						timer = window.setInterval("Refresh()", t);
					} else {
						var parentId = ChildDiv.parentNode.parentNode.parentNode.id.split('|')[1];
						SubNodeHash.get(parentId)[1].set(id, null);
					}
				} else {
					UnsetSubs(id);
				}
				var text = transport.responseText.split('*');
				if (text[0] == "" && text[1] == "") {
					ChildDiv.innerHTML = "";
				} else {
					Display(text, ChildDiv);
				}
				ZhedieIco.alt = "折叠";
				ZhedieIco.src = imgCollapseUrl;
				ZhedieIco.style.cursor = "pointer";
				ZhedieIco.style.visibility = "";
				ZhedieIco.onclick = function () { newclick(this) };
				ZhedieIco.nextSibling.ondblclick = function () { LoadNode(this, true); };

				ChildDiv.style.display = "block";
				SetOperationFocus(o.parentNode);
				var FinishTime_S = new Date().getTime();
				var DisplayTime = FinishTime_S - LoadedTime_S;
				var FinishTime = FinishTime_S - StartLoadTime_S;
				LoadMessage += "，呈现用时：" + DisplayTime + " ms，" + "总用时：" + FinishTime + " 毫秒";
			}
		}
		function Display(text, ChildDiv) {
			var Checked = ChildDiv.previousSibling.childNodes[2].checked;
			var a = new Array();
			if (text[0] != "") a[0] = GroupNodeHtml(text[0]);
			if (text[1] != "") a[1] = userNodeHtml(text[1]);
			ChildDiv.innerHTML = a.join("");
			a = null;
			function GroupNodeHtml(str) {
				var a = new Array();
				a[0] = "<ul class=\"" + GroupListClass + "\">";
				var rows = str.split('?');
				for (var i = 0; i < rows.length - 1; i++) {
					var info = rows[i].split('|');
					var GroupID = info[0];
					var GroupName = info[1];
					GroupNameHash.set(GroupID, GroupName);
					a[i + 1] = "<li id=\"" + GroupID + "\">" + getGroupsDivHtml(GroupID, Checked, GroupName) + "</li>";
				}
				a[rows.length] = "</ul>";
				var html = a.join("");
				a = null;
				return html;
			}
			function userNodeHtml(str) {
				var a = new Array();
				a[0] = "<ul class=\"" + ObjectListClass + "\">";
				var rows = str.split('?');
				for (var i = 0; i < rows.length - 1; i++) {
					var info = rows[i].split('|');
					var ObjectID = info[0];
					var ObjectName = info[1];
					var ObjectIcon;
					var ExtNames = ObjectName.split('.');
					if (ExtNames.length == 1) {
						ObjectIcon = getStatusIco("Unkown");
					} else {
						ObjectIcon = getStatusIco(ExtNames[ExtNames.length - 1]);
					}
					a[i + 1] = "<li id=\"" + ObjectID + "\">" + getObjectsDivHtml(ObjectID, Checked, ObjectName, ObjectIcon) + "</li>";
				}
				a[rows.length] = "</ul>";
				var html = a.join("");
				a = null;
				return html;
			}
		}
		function reportError(transport) {
			alert("Sorry! 服务器错误：" + transport.status + "，请求失败！\n\n" + transport.responseText);
		}
		function newclick(o) {
			var ChildDiv = o.parentNode.nextSibling;
			if (ChildDiv.style.display == "block") {
				ChildDiv.style.display = "none";
				o.alt = "展开";
				o.setAttribute("src", imgExpandUrl);
			}
			else if (ChildDiv.style.display == "none") {
				ChildDiv.style.display = "block";
				o.alt = "折叠";
				o.setAttribute("src", imgCollapseUrl);
			}
		}
		function Refresh() {
			var RefreshMessage = "刷新所有节点";
			var StartRefreshTime_S, LoadedTime_S;
			StatusBarDiv.firstChild.data = RefreshMessage;
			var loadedtime;
			var ids = SubNodeHash.keys().join('|');
			var nodes = SubNodeHash.values();
			var postbody = "act=RefreshNodes&ids=" + ids;
			new Ajax.Request(url, {
				method: 'post',
				postBody: postbody,
				onCreate: function () {
					StartRefreshTime_S = new Date().getTime();
				},
				onLoaded: function () {
					LoadedTime_S = new Date().getTime();
					var LoadedTime = LoadedTime_S - StartRefreshTime_S;
					RefreshMessage += "，传输用时：" + LoadedTime + "毫秒";
				},
				onFailure: function () {
					window.clearInterval(timer);
					reportError(transport);
				},
				onSuccess: function (transport) {
					var texts = transport.responseText.split('\n');
					for (var i = 0; i < texts.length - 1; i++) {
						var ChildDiv = (nodes[i])[0];
						var text = texts[i];
						if (ChildDiv.previousSibling) Compare(text, ChildDiv);  //!!!!
					}
					var FinishTime_S = new Date().getTime();
					var DisplayTime = FinishTime_S - LoadedTime_S;
					var FinishTime = FinishTime_S - StartRefreshTime_S;
					RefreshMessage += "，呈现用时：" + DisplayTime + " ms，" + "总用时：" + FinishTime + " 毫秒";
				},
				onComplete: function () { StatusBarDiv.firstChild.data = RefreshMessage; }
			});
		}
		function RefreshNode(ChildDiv) {
			var id = ChildDiv.id.split('|')[1];
			var postbody = 'act=LoadNode&id=' + id;
			new Ajax.Request(url, {
				method: 'post',
				postBody: postbody,
				onFailure: reportError,
				onSuccess: function (transport) {
					var text = transport.responseText;
					Compare(text, ChildDiv);
				}
			});
		}
		function Compare(str, ChildDiv) {
			var text = str.split('*');
			var ZhedieIco = ChildDiv.previousSibling.firstChild;
			var checked = ChildDiv.previousSibling.childNodes[2].checked;
			if (text[0] == "" && text[1] == "") {
				if (ChildDiv.hasChildNodes()) ChildDiv.innerHTML = "";
				UnsetSubs(ChildDiv.id.split('|')[1]);
			} else {
				var children = ChildDiv.childNodes.length;
				if (text[0] != "") {
					if (children == 0) {
						var GroupUl = document.createElement("ul");
						GroupUl.className = GroupListClass;
						ChildDiv.appendChild(GroupUl);
					} else if (children == 1) {
						if (ChildDiv.firstChild.className != GroupListClass) {
							var GroupUl = document.createElement("ul");
							GroupUl.className = GroupListClass;
							ChildDiv.insertBefore(GroupUl, ChildDiv.lastChild);
						}
					}
					CompareGroupNode(text[0], ChildDiv.firstChild);
				} else {
					if (children == 2) {
						ChildDiv.removeChild(ChildDiv.firstChild);
					} else if (children == 1) {
						if (ChildDiv.firstChild.className == GroupListClass) {
							ChildDiv.removeChild(ChildDiv.firstChild);
						}
					}
					UnsetSubs(ChildDiv.id.split('|')[1]);
				}
				if (text[1] != "") {
					if (children == 0) {
						var ObjectUl = document.createElement("ul");
						ObjectUl.className = ObjectListClass;
						ChildDiv.appendChild(ObjectUl);
					} else if (children == 1) {
						if (ChildDiv.lastChild.className != ObjectListClass) {
							var ObjectUl = document.createElement("ul");
							ObjectUl.className = ObjectListClass;
							ChildDiv.appendChild(ObjectUl);
						}
					}
					CompareObjectNode(text[1], ChildDiv.lastChild);
				} else {
					if (children == 2) {
						ChildDiv.removeChild(ChildDiv.lastChild);
					} else if (children == 1) {
						if (ChildDiv.lastChild.className == ObjectListClass) {
							ChildDiv.removeChild(ChildDiv.lastChild);
						}
					}
				}
			}
			function CompareGroupNode(groupsText, ul) {
				var rows = groupsText.split('?');
				var lis = ul.childNodes;
				var i = 0;
				var j = 0;
				while (i < rows.length - 1 && j < lis.length) {
					var info = rows[i].split('|');
					var GroupID = info[0];
					var LiId = lis[j].id;
					if (GroupID.toLowerCase() == LiId.toLowerCase()) {
						if (GroupNameHash.get(GroupID) != info[1]) {
							lis[j].firstChild.childNodes[3].firstChild.firstChild.data = info[1];
							GroupNameHash.set(GroupID, info[1]);
						}
						i++; j++;
						continue;
					}
					if (GroupID.toLowerCase() > LiId.toLowerCase()) {
						ul.removeChild(lis[j]);
						GroupNameHash.unset(LiId);
						continue;
					}
					if (GroupID.toLowerCase() < LiId.toLowerCase()) {
						var li = document.createElement("li");
						li.id = GroupID;
						var GroupName = info[1];
						GroupNameHash.set(GroupID, GroupName);
						li.innerHTML = getGroupsDivHtml(GroupID, checked, GroupName);
						ul.insertBefore(li, lis[j]);
						i++; j++;
						continue;
					}
				}
				for (; i < rows.length - 1; i++) {
					var info = rows[i].split('|');
					var GroupID = info[0];
					var GroupName = info[1];
					GroupNameHash.set(GroupID, GroupName);
					var li = document.createElement("li");
					li.id = GroupID;
					li.innerHTML = getGroupsDivHtml(GroupID, checked, GroupName);
					ul.appendChild(li);
					j++;
				}
				for (; j < lis.length; j++) {
					ul.removeChild(lis[j]);
					GroupNameHash.unset(LiId);
				}
			}
			function CompareObjectNode(objectsText, ul) {
				var rows = objectsText.split('?');
				var lis = ul.childNodes;
				var i = 0;
				var j = 0;
				while (i < rows.length - 1 && j < lis.length) {
					var info = rows[i].split('|');
					var ObjectID = info[0];
					var ObjectName = info[1];
					var ObjectStatus = info[2];
					var ObjectIcon;
					var ExtNames = ObjectName.split('.');
					if (ExtNames.length == 1) {
						ObjectIcon = getStatusIco("Unkown");
					} else {
						ObjectIcon = getStatusIco(ExtNames[ExtNames.length - 1]);
					}
					var LiId = lis[j].id;
					if (ObjectID.toLowerCase() == LiId.toLowerCase()) {
						if (ObjectNameHash.get(ObjectID) != ObjectName) {
							lis[j].firstChild.childNodes[2].firstChild.firstChild.data = ObjectName;
							ObjectNameHash.set(ObjectID, ObjectName);
						}
						if (ObjectIconHash.get(ObjectID) != ObjectIcon) {
							lis[j].firstChild.childNodes[0].src = ObjectIcon;
							ObjectIconHash.set(ObjectID, ObjectIcon);
						}
						i++; j++;
						continue;
					}
					if (ObjectID.toLowerCase() > LiId.toLowerCase()) {
						ul.removeChild(lis[j]);
						ObjectNameHash.unset(LiId);
						ObjectIconHash.unset(LiId);
						continue;
					}
					if (ObjectID.toLowerCase() < LiId.toLowerCase()) {
						var li = document.createElement("li");
						li.id = ObjectID;
						li.innerHTML = getObjectsDivHtml(ObjectID, checked, ObjectName, ObjectIcon);
						ul.insertBefore(li, lis[j]);
						i++; j++;
						continue;
					}
				}
				for (; i < rows.length - 1; i++) {
					var info = rows[i].split('|');
					var ObjectID = info[0];
					var ObjectName = info[1];
					var ObjectStatus = info[2];
					var ObjectIcon;
					var ExtNames = ObjectName.split('.');
					if (ExtNames.length == 1) {
						ObjectIcon = getStatusIco("Unkown");
					} else {
						ObjectIcon = getStatusIco(ExtNames[ExtNames.length - 1]);
					}
					var li = document.createElement("li");
					li.id = ObjectID;
					li.innerHTML = getObjectsDivHtml(ObjectID, checked, ObjectName, ObjectIcon);
					ul.appendChild(li);
					j++;
				}
				for (; j < lis.length; j++) {
					ul.removeChild(lis[j]);
					ObjectNameHash.unset(LiId);
					ObjectIconHash.unset(LiId);
				}
			}
		}
		var CheckedGroups = new Hash();
		var CheckedObjects = new Hash();
		function checkBox(o) {
			var CheckType = o.parentNode.parentNode.parentNode.className;
			if (CheckType == ObjectListClass) {
				if (o.checked == true) CheckedObjects.set(o.name, o.nextSibling.firstChild.firstChild.data);
				if (o.checked == false) CheckedObjects.unset(o.name, o.nextSibling.firstChild.firstChild.data);
				SetParentCheckBox(o);
			}
			if (CheckType == GroupListClass) {
				if (o.checked == true) CheckedGroups.set(o.name, o.nextSibling.firstChild.firstChild.data);
				if (o.checked == false) CheckedGroups.unset(o.name, o.nextSibling.firstChild.firstChild.data);
				var StartSelectTime_S = new Date().getTime();
				var ChildDiv = o.parentNode.nextSibling;
				var checkboxs = ChildDiv.getElementsByTagName("input");
				for (var i = 0; i < checkboxs.length; i++) {
					if (checkboxs[i].parentNode.parentNode.parentNode.className == GroupListClass) {
						if (o.checked == true) CheckedGroups.set(checkboxs[i].name, checkboxs[i].nextSibling.firstChild.firstChild.data);
						if (o.checked == false) CheckedGroups.unset(checkboxs[i].name, checkboxs[i].nextSibling.firstChild.firstChild.data);
					}
					if (checkboxs[i].parentNode.parentNode.parentNode.className == ObjectListClass) {
						if (o.checked == true) CheckedObjects.set(checkboxs[i].name, checkboxs[i].nextSibling.firstChild.firstChild.data);
						if (o.checked == false) CheckedObjects.unset(checkboxs[i].name, checkboxs[i].nextSibling.firstChild.firstChild.data);
					}
					checkboxs[i].checked = o.checked;
				}
				SetParentCheckBox(o);
				var SelectEndTime_S = new Date().getTime();
				var spendtime = SelectEndTime_S - StartSelectTime_S;
				//StatusBarDiv.firstChild.data="全选 "+o.nextSibling.firstChild.firstChild.data+" 历时："+spendtime+"毫秒\n";
			}

			function SetParentCheckBox(obj) {
				if (obj.parentNode.parentNode.parentNode.parentNode.previousSibling) {
					var ParentCheckbox = obj.parentNode.parentNode.parentNode.parentNode.previousSibling.childNodes[2];
					if (ParentCheckbox.checked == true && obj.checked == false) {
						ParentCheckbox.checked = false;
						SetParentCheckBox(ParentCheckbox); //递归
					}
					if (ParentCheckbox.checked == false && obj.checked == true) {
						var ParentChildDiv = obj.parentNode.parentNode.parentNode.parentNode;
						var checkboxs = ParentChildDiv.getElementsByTagName("input");
						var isChecked = true;
						for (var i = 0; i < checkboxs.length; i++) {
							if (checkboxs[i].checked == false) {
								isChecked = false;
								break;
							}
							isChecked = isChecked && checkboxs[i].checked;
						}
						ParentCheckbox.checked = isChecked;
						SetParentCheckBox(ParentCheckbox); //递归
						if (isChecked == true) CheckedGroups.set(ParentCheckbox.name, ParentCheckbox.nextSibling.firstChild.firstChild.data);
						if (isChecked == false) CheckedGroups.unset(ParentCheckbox.name, ParentCheckbox.nextSibling.firstChild.firstChild.data);
					}
				}
			}
		}
		function Login_onsubmit() {
			var postbody = "act=login&username=" + $F("username") + "&password=" + $F("password");
			new Ajax.Request(url, {
				method: "post",
				postBody: postbody,
				onCreate: function () { },
				onFailure: reportError,
				onSuccess: function (transport) {
					if (transport.responseText.split(":")[0] == "ok") {
						$("loginstatus").innerHTML = "登录成功" + "<input type=\"button\" value=\"登出\" onclick=\"logout();\" />";
						$("loginDiv").parentNode.removeChild($("loginDiv"));
						RootNode.id = transport.responseText.split(":")[2];
						RootNode.innerHTML = getGroupsDivHtml(RootNode.id, false, RootNode.id);
						LoadNode(RootNode.firstChild.firstChild);
					} else {
						$("loginstatus").innerHTML = "登录失败";
					}
				}
			});
			return false;
		}
		function logout() {
			var postbody = "act=logout";
			new Ajax.Request(url, {
				method: "post",
				postBody: postbody,
				onCreate: function () { },
				onFailure: reportError,
				onSuccess: function (transport) {
					location.reload();
				}
			});
		}
		function SetTime_onclick(o) {
			window.clearInterval(timer);
			var x = parseInt(o.previousSibling.previousSibling.value) * 1000;
			t = isNaN(x) ? t : x;
			timer = window.setInterval("Refresh()", t);
		}
		function UnsetSubs(id) {
			var h = SubNodeHash.get(id)[1];
			var k = h.keys();
			for (var i = 0; i < k.length; i++) {
				UnsetSubs(k[i]);
				h.unset(k[i]);
				SubNodeHash.unset(k[i]);
			}
		}
		function Create(type, newName, OperationBoxLi) {
			$("NewFolderName").value = "";
			$("NewFolderDialog").style.visibility = "hidden";
			var pathName = OperationBoxLi.id + newName;
			var act = "Create" + type;
			new Ajax.Request(url, {
				method: "post",
				postBody: "act=" + act + "&pathName=" + pathName,
				onFailure: function (transport) {
					reportError(transport);
				},
				onSuccess: function (transport) {
					RefreshNode(OperationBoxLi.childNodes[1]);
					StatusBarDiv.firstChild.data = ("新建成功");
				},
				onComplete: function () { }
			});
		}
		function Delete(ChildDiv) {
			var name = ChildDiv.lastChild.firstChild.firstChild.data;
			var result = window.confirm("你确定要永久删除 " + name + " 吗？");
			if (result) {
				var type = ChildDiv.parentNode.parentNode.className;
				var act = "Delete" + type;
				var pathName = ChildDiv.parentNode.id;
				new Ajax.Request(url, {
					method: "post",
					postBody: "act=" + act + "&pathName=" + pathName,
					onFailure: function (transport) {
						reportError(transport);
					},
					onSuccess: function (transport) {
						var ParentDiv = ChildDiv.parentNode.parentNode.parentNode;
						RefreshNode(ParentDiv);
					},
					onComplete: function () { }
				});
			}
		}
		function Rename(ChildDiv) {
			var namespan = ChildDiv.lastChild.firstChild;
			var textbox = document.createElement("input");
			textbox.type = "text";
			textbox.value = namespan.firstChild.data;
			namespan.style.display = "none";
			namespan.parentNode.appendChild(textbox);
			textbox.focus();
			textbox.oncontextmenu = function (event) {
				if (window.event) {
					window.event.cancelBubble = true;
				} else {
					event.stopPropagation();
				}
			};
			textbox.onblur = function () {
				DoRename();
			};
			textbox.onkeydown = function (event) {
				event = window.event || event;
				if (event.keyCode == 13) {
					DoRename();
					return false;
				} else if (event.keyCode == 27) {
					clearRename();
				}
			};
			function DoRename() {
				if (textbox.value != namespan.firstChild.data) {
					var act;
					var type = ChildDiv.parentNode.parentNode.className;
					act = "Move" + type;
					var sourceName = encodeURIComponent(ChildDiv.parentNode.id);
					var newName = encodeURIComponent(ChildDiv.parentNode.parentNode.parentNode.parentNode.id + textbox.value);
					var postBody = "act=" + act + "&sourceName=" + sourceName + "&newName=" + newName;
					new Ajax.Request(url, {
						method: "post",
						postBody: postBody,
						onFailure: function (transport) {
							textbox.onblur = null;
							reportError(transport);
							textbox.onblur = function () { DoRename(); };
						},
						onSuccess: function (transport) {
							clearRename();
							var ParentDiv = ChildDiv.parentNode.parentNode.parentNode;
							RefreshNode(ParentDiv);
							//namespan.firstChild.data=textbox.value;
						},
						onComplete: function (transport) { }
					});
				} else {
					clearRename();
				}
			}
			function clearRename() {
				textbox.onblur = null;
				textbox.parentNode.removeChild(textbox);
				namespan.style.display = "";
			}
		}

		var OperationBoxLi = null;
		var OperationDiv = null;

		function SetOperationFocus(o) {
			if (OperationDiv != null) {
				OperationDiv.className = "";
			}
			if (OperationBoxLi != null) {
				OperationBoxLi.className = "";
				OperationBoxLi.firstChild.className = "";
			}
			OperationDiv = o;
			OperationDiv.className = "OperationDiv";

			if (o.parentNode.parentNode.className == GroupListClass) {
				if (o.nextSibling.style.display == "block") {
					OperationBoxLi = o.parentNode;
				} else {
					OperationBoxLi = o.parentNode.parentNode.parentNode.parentNode;
				}
				OperationBoxLi.className = "OperationBoxLi";
				OperationBoxLi.firstChild.className = "OperationBoxLiTitleDiv";
				$("FolderPath").value = OperationBoxLi.id;
				$("FilePath").value = o.lastChild.firstChild.firstChild.data;
				$("FolderPath").value = OperationBoxLi.id;
				$("FilePath").value = o.lastChild.firstChild.firstChild.data;
			}
			if (o.parentNode.parentNode.className == ObjectListClass) {
				OperationBoxLi = o.parentNode.parentNode.parentNode.parentNode;
				OperationBoxLi.className = "OperationBoxLi";
				OperationBoxLi.firstChild.className = "OperationBoxLiTitleDiv";

				$("FolderPath").value = OperationBoxLi.id;
				$("FilePath").value = o.lastChild.firstChild.firstChild.data;
			}
		}
		var BodyWidth, BodyHeight;
		var LastPoint_x, LastPoint_y;
		function Menu_1(event) {
			BodyWidth = document.body.clientWidth;
			BodyHeight = document.body.clientHeight != 0 ? document.body.clientHeight : $("MainBody").clientHeight; //document.documentElement.clientHeight 
			LastPoint_x = event.clientX + document.body.scrollLeft;
			LastPoint_y = event.clientY + document.body.scrollTop;
			var MenuWidth = $("Menu_1").clientWidth;
			var MenuHeight = $("Menu_1").clientHeight;
			//StatusBarDiv.innerHTML="mw:"+mw+"; mh:"+mh+"; x:"+x+"; y:"+y+"; w:"+w+"; h:"+h;
			$("Menu_1").style.left = Position_x(MenuWidth);
			$("Menu_1").style.top = Position_y(MenuHeight);
			$("Menu_1").style.visibility = "visible";
			return false;
		}
		function Position_x(width) {
			if (LastPoint_x < width) {
				return LastPoint_x.toString() + "px";
			} else {
				if (BodyWidth - LastPoint_x < width) {
					return (LastPoint_x - width).toString() + "px";
				} else {
					return LastPoint_x.toString() + "px";
				}
			}
		}
		function Position_y(height) {
			if (LastPoint_y < height) {
				return LastPoint_y.toString() + "px";
			} else {
				if (BodyHeight - LastPoint_y < height) {
					return (LastPoint_y - height).toString() + "px";
				} else {
					return LastPoint_y.toString() + "px";
				}
			}
		}
		function DoMenu_1() {
			ClearMenu();
			return false;
		}
		function ClearSelected() {
			ClearMenu();
			OperationDiv.className = "";
			OperationDiv = null;
			return false;
		}
		function onBodyKeyDown(event) {
			event = window.event || event;
			if (event.keyCode == 27) {
				ClearMenu();
			}
		}
		function ClearMenu(o, event) {
			$("Menu_1").style.visibility = "hidden";
			if (typeof (o) != 'undefined') {
				o.parentNode.parentNode.style.visibility = "hidden";
			}
			if (typeof (event) != 'undefined') {
				if (window.event) {
					window.event.cancelBubble = true;
				} else {
					event.stopPropagation();
				}
			}
		}
		function ShowChildMenu(o) {
			var ChildMenuDiv = o.firstChild;
			if (o.firstChild.nodeName == "#text") ChildMenuDiv = ChildMenuDiv.nextSibling;
			ChildMenuDiv.style.visibility = "visible";
		}
		function HideChildMenu(o) {
			var ChildMenuDiv = o.firstChild;
			if (o.firstChild.nodeName == "#text") ChildMenuDiv = ChildMenuDiv.nextSibling;
			ChildMenuDiv.style.visibility = "hidden";
		}
		function ShowCreateDialog(type, MenuLi) {
			ClearMenu();
			var NewFolderDialogDiv = $("NewFolderDialog");
			var Width = NewFolderDialogDiv.clientWidth;
			var Height = NewFolderDialogDiv.clientHeight;
			NewFolderDialogDiv.style.left = Position_x(Width);
			NewFolderDialogDiv.style.top = Position_y(Height);
			$("CreateTitle").firstChild.data = MenuLi.firstChild.firstChild.firstChild.firstChild.data;
			$("CreateFrom").onsubmit = function () { Create(type, $('NewFolderName').value, OperationBoxLi); return false; };
			NewFolderDialogDiv.style.visibility = "visible";
			$("NewFolderName").focus();
		}
		function Download(o) {
			if (o.parentNode.parentNode.className == ObjectListClass) {
				var path = encodeURIComponent(o.parentNode.id);
				var DownWin = window.open(location.href + "?act=download&path=" + path);
				DownWin.onload = function () { DownWin.close(true); };
			}
			return false;
		}
		function ViewSeleted() {
			if (OperationDiv.parentNode.parentNode.className == ObjectListClass) {
				window.open(OperationDiv.childNodes[2].firstChild.href);
			}
		}
		function open_win() {
			var newWin = window.open("HTMLPage2.htm", "_blank", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
			//newWin.window.blur();
			//window.focus();
		}
		function PageTitlesMoveRight() {
			var marginLeft = PageTitlesOuter.style.marginLeft == "" ? 0 : parseFloat(PageTitlesOuter.style.marginLeft.split("em")[0]);
			var HiddenLength = PageTitlesFloater.clientWidth + marginLeft * 16 - PageTitlesDoor.clientWidth;
			if (HiddenLength > 256) {
				PageTitlesOuter.style.marginLeft = (marginLeft - 16) + "em";
			} else if (HiddenLength <= 256) {
				PageTitlesOuter.style.marginLeft = (marginLeft - HiddenLength / 16) + "em";
			} else { }
		}
		function PageTitlesMoveLeft() {
			var marginLeft = PageTitlesOuter.style.marginLeft == "" ? 0 : parseFloat(PageTitlesOuter.style.marginLeft.split("em")[0]);
			var HiddenLength = PageTitlesFloater.clientWidth + marginLeft * 16 - PageTitlesDoor.clientWidth;
			if (marginLeft * 16 < -256) {
				PageTitlesOuter.style.marginLeft = (marginLeft + 16) + "em";
			} else if (marginLeft * 16 >= -256) {
				PageTitlesOuter.style.marginLeft = "0em";
			}
		}
		function PageClose(PageId) {
			var TitleDiv = Pages.get(PageId)[0];
			var PageDiv = Pages.get(PageId)[1];
			TitleDiv.parentNode.removeChild(TitleDiv);
			PageDiv.parentNode.removeChild(PageDiv);
			Pages.unset(PageId);
			if (CurentPageTitle.id == PageId) {
				if (Pages.values().length > 0) {
					CurentPageTitle = (Pages.values()[Pages.values().length - 1])[0];
					CurentPage = (Pages.values()[Pages.values().length - 1])[1];
					CurentPageTitle.className = "PageTitleActive";
					CurentPage.style.display = "";
				}
			}
			return false;
		}
		function SwitchPage(PageId) {
			var TitleDiv = Pages.get(PageId)[0];
			if (CurentPageTitle.id != PageId) {
				var PageDiv = Pages.get(PageId)[1];
				CurentPageTitle.className = "PageTitle";
				CurentPage.style.display = "none";
				TitleDiv.className = "PageTitleActive";
				PageDiv.style.display = "";
				CurentPageTitle = TitleDiv;
				CurentPage = PageDiv;
			}
			var leftLength = 0;
			for (var i = 0; i < TitleDiv.parentNode.childNodes.length; i++) {
				if (TitleDiv == PageTitlesFloater.childNodes[i]) break;
				leftLength += PageTitlesFloater.childNodes[i].clientWidth;
			}
			var marginLeftPx = PageTitlesOuter.style.marginLeft == "" ? 0 : parseFloat(PageTitlesOuter.style.marginLeft.split("em")[0]) * 16;
			if (leftLength + marginLeftPx < 0) {
				PageTitlesOuter.style.marginLeft = (-leftLength / 16) + "em";
			}
			var rightLength = leftLength + TitleDiv.clientWidth;
			if (rightLength > PageTitlesDoor.clientWidth - marginLeftPx) {
				PageTitlesOuter.style.marginLeft = (PageTitlesDoor.clientWidth - rightLength) / 16 + "em";
			}
		}
		function EditFile(o, CodePage) {
			var pathName = o.parentNode.id;
			var PageId = "Edit:" + pathName;
			if (Pages.keys().indexOf(PageId) == -1) {
				var PageTitle = document.createElement("div");
				PageTitle.id = PageId;
				PageTitle.onclick = function () { SwitchPage(this.id); };
				PageTitle.title = pathName;
				PageTitle.innerHTML = "<a href=\"#\" onfocus=\"this.blur();\" onclick=\"return false;\"><span class=\"PageCloseButton\" title=\"关闭\" onclick=\"return PageClose(this.parentNode.parentNode.id);\">×</span><span class=\"PageTitleBg0\"><span class=\"PageTitleBg1\"><span class=\"PageTitleBg2\">Page Title</span></span></span></a>";
				PageTitle.firstChild.lastChild.firstChild.firstChild.firstChild.data = pathName;
				PageTitlesFloater.insertBefore(PageTitle, PageTitlesFloater.firstChild);
				PageTitlesOuter.style.marginLeft = "0em";
				var Page = document.createElement("div");
				Page.className = "inside";
				Page.style.zIndex = 100;
				Page.style.overflow = "hidden";
				$("ContentWindow").appendChild(Page);
				var EditFrame = document.createElement("iframe");
				EditFrame.name = "EditFrame|" + pathName;
				EditFrame.src = "EditFile.aspx?path=" + encodeURIComponent(pathName) + "&CodePage=" + CodePage;
				EditFrame.frameBorder = "0";
				EditFrame.scrolling = "auto";
				EditFrame.style.width = "100%";
				EditFrame.style.height = "100%";
				EditFrame.style.position = "absolute";
				Page.appendChild(EditFrame);
				Pages.set(PageTitle.id, [PageTitle, Page]);
			}
			SwitchPage(PageId);
		}
		function UploadFiles(o) {
			var path = o.parentNode.id;
			var PageId = "Upload:" + path;
			if (Pages.keys().indexOf(PageId) == -1) {
				var PageTitle = document.createElement("div");
				PageTitle.id = PageId;
				PageTitle.onclick = function () { SwitchPage(this.id); };
				PageTitle.title = "上传至" + path;
				PageTitle.innerHTML = "<a href=\"#\" onfocus=\"this.blur();\" onclick=\"return false;\"><span class=\"PageCloseButton\" title=\"关闭\" onclick=\"return PageClose(this.parentNode.parentNode.id);\">×</span><span class=\"PageTitleBg0\"><span class=\"PageTitleBg1\"><span class=\"PageTitleBg2\">Page Title</span></span></span></a>";
				PageTitle.firstChild.lastChild.firstChild.firstChild.firstChild.data = "上传文件";
				PageTitlesFloater.insertBefore(PageTitle, PageTitlesFloater.firstChild);
				PageTitlesOuter.style.marginLeft = "0em";
				var Page = document.createElement("div");
				Page.className = "inside";
				Page.style.zIndex = 100;
				Page.style.overflow = "hidden";
				$("ContentWindow").appendChild(Page);
				var EditFrame = document.createElement("iframe");
				EditFrame.name = "UploadFrame|" + path;
				EditFrame.src = "UploadFiles.aspx?path=" + encodeURIComponent(path);
				EditFrame.frameBorder = "0";
				EditFrame.scrolling = "auto";
				EditFrame.style.width = "100%";
				EditFrame.style.height = "100%";
				EditFrame.style.position = "absolute";
				Page.appendChild(EditFrame);
				Pages.set(PageTitle.id, [PageTitle, Page]);
			}
			SwitchPage(PageId);
		}
//]]>
	</script>
</head>
<body onload="pageOnload()" onkeydown="onBodyKeyDown(event);">
	<div id="contextMenus" oncontextmenu="return false;">
		<div id="Menu_1" class="rightMenu" style="visibility: hidden;">
			<ul>
				<li onclick="ViewSeleted();return false;">
					<div>
						<a href="#" onclick="return false;" onfocus="this.blur();"><span>浏览（新窗口）</span></a></div>
				</li>
				<li onclick="ShowChildMenu(this);" onmouseover="ShowChildMenu(this);" onmouseout="HideChildMenu(this);">
					<div style="left: 110px; visibility: hidden;" class="rightMenu">
						<ul style="margin: 0; padding: 0;">
							<li onclick="ClearMenu(this,event);EditFile(OperationDiv,936);">
								<div>	
									<a href="#" onclick="return false;"><span>纯文本编辑（GB2312）</span></a></div>
							</li>
							<li onclick="ClearMenu(this,event);EditFile(OperationDiv,65001);">
								<div>
									<a href="#" onclick="return false;"><span>纯文本编辑（UTF-8）</span></a></div>
							</li>
							<li onclick="ClearMenu(this,event);EditFile(OperationDiv,54936);">
								<div>
									<a href="#" onclick="return false;"><span>纯文本编辑（GB18030）</span></a></div>
							</li>
							<li onclick="ClearMenu(this,event);var code=prompt('请输入编码','65001');EditFile(OperationDiv,code);">
								<div>
									<a href="#" onclick="return false;"><span>特定编码编辑（请输入…）</span></a></div>
							</li>
							<li onclick="ClearMenu(this,event);">
								<div>
									<a href="#" onclick="return false;"><span>富文本编辑（FCKeditor）</span></a></div>
							</li>
							<li onclick="ClearMenu(this,event);">
								<div>
									<a href="#" onclick="return false;"><span>粘贴</span></a></div>
							</li>
							<li onclick="ClearMenu(this,event);">
								<div>
									<a href="#" onclick="return false;"><span>剪切</span></a></div>
							</li>
						</ul>
					</div>
					<div>
						<a href="#" onclick="return false;" onfocus="this.blur();"><span>编辑 → ＞</span></a></div>
				</li>
				<li onclick="ShowCreateDialog(GroupListClass,this);">
					<div>
						<a href="#" onclick="return false;"><span>新建文件夹</span></a></div>
				</li>
				<li onclick="ShowCreateDialog(ObjectListClass,this);">
					<div>
						<a href="#" onclick="return false;"><span>新建文件</span></a></div>
				</li>
			</ul>
			<ul>
				<li onclick="ClearMenu();return Rename(OperationDiv);">
					<div>
						<a href="#" onclick="return false;"><span>重命名</span></a></div>
				</li>
				<li onclick="ClearMenu();return Delete(OperationDiv);">
					<div>
						<a href="#" onclick="return false;"><span>删除</span></a></div>
				</li>
				<li onclick="return DoMenu_1();">
					<div>
						<a href="#" onclick="return false;"><span>复制</span></a></div>
				</li>
				<li onclick="return DoMenu_1();">
					<div>
						<a href="#" onclick="return false;"><span>粘贴</span></a></div>
				</li>
				<li onclick="return DoMenu_1();">
					<div>
						<a href="#" onclick="return false;"><span>剪切</span></a></div>
				</li>
			</ul>
			<ul>
				<li onclick="ClearMenu();return Download(OperationDiv);">
					<div>
						<a href="#" onclick="return false;"><span>下载</span></a></div>
				</li>
				<li onclick="ClearMenu(this,event);UploadFiles(OperationDiv);">
					<div>
						<a href="#" onclick="return false;"><span>上传</span></a></div>
				</li>
				<li onclick="location.reload();">
					<div>
						<a href="#" onclick="return false;"><span>刷新</span></a></div>
				</li>
			</ul>
		</div>
	</div>
	<div id="OperationArea">
		<div id="NewFolderDialog" style="visibility: hidden; position: absolute; z-index: 100; padding: 5px; background: #eee; border: #888 2px outset;">
			<form id="CreateFrom" action="">
			<div id="CreateTitle">
				新建目录</div>
			<div>
				<input type="text" id="NewFolderName" /><br />
				<input type="submit" value="确定" />
				<input type="button" value="取消" onclick="this.parentNode.parentNode.parentNode.style.visibility='hidden';" />
			</div>
			</form>
		</div>
	</div>
	<div id="MainBody" onmousedown="ClearMenu();">
		<div id="header">
			<h1>
				Files Operator 文件浏览器</h1>
		</div>
		<div id="loginBox">
			<form id="Login" onsubmit="return Login_onsubmit()" action="">
			<%if ((UserEntry)Session["logined"] == null)
	 {%>
			<div id="loginDiv">
				<label for="username">
					用户：</label><input type="text" id="username" name="username" value="admin" /><br />
				<label for="password">
					密码：</label><input type="password" id="password" name="password" value="admin" /><br />
				<input id="submitbutton" type="submit" value="登录" />
			</div>
			<%}%>
			<div id="loginstatus">
				<%if ((UserEntry)Session["logined"] != null)
	  {%><input type="button" value="登出" onclick="logout();" /><%}%></div>
			</form>
		</div>
		<div id="folderToolBar">
			<input title="刷新" onclick="Refresh();" type="button" style="width: 36px; height: 36px; background: url(images/refresh.gif)" />
			<input disabled="disabled" type="button" title="删除" style="width: 36px; height: 36px; background: url(images/del.gif)" />
			<input disabled="disabled" type="button" title="复制" style="width: 36px; height: 36px; background: url(images/copy.gif)" />
			<input disabled="disabled" type="button" title="剪切" style="width: 36px; height: 36px; background: url(images/cut.gif)" />
			<input disabled="disabled" type="button" title="粘贴" style="width: 36px; height: 36px; background: url(images/paste.gif)" />
			<input disabled="disabled" type="button" title="压缩" style="width: 36px; height: 36px; background: url(images/RarAdd.gif)" />
			<input disabled="disabled" type="button" title="解压" style="width: 36px; height: 36px; background: url(images/RarExt.gif)" />
		</div>
		<div id="folderDiv">
			<div class="inner">
				<div class="inside">
					<ul class="<%=GroupListClass%>">
						<li id="RootNode"></li>
					</ul>
				</div>
			</div>
		</div>
		<div id="PageTitles">
			<div id="PageTitlesList">
				▼</div>
			<div id="PageTitlesMoveLeft" onclick="PageTitlesMoveLeft();">
				﹤</div>
			<div id="PageTitlesMoveRight" onclick="PageTitlesMoveRight();">
				﹥</div>
			<div id="PageTitlesDoor">
				<div id="PageTitlesOuter">
					<div id="PageTitlesFloater">
						<div onclick="SwitchPage(this.id);" class="PageTitleActive" id="StartPageTitle" title="起始页">
							<a href="#" onfocus="this.blur();" onclick="return false;">
								<!--<span class="PageCloseButton" title="关闭" onclick="return PageClose(this.parentNode.parentNode.id);">×</span>-->
								<span class="PageTitleBg0"><span class="PageTitleBg1"><span class="PageTitleBg2">起始页</span></span></span></a></div>
						<!--<div class="PageTitle" title="我的标题title"><a href="#" onfocus="this.blur();" onclick="return false;"><span class="PageCloseButton" title="关闭" onclick="">×</span><span class="PageTitleBg0"><span class="PageTitleBg1"><span class="PageTitleBg2">我的标题</span></span></span></a></div>
                <div class="PageTitle" title="我的标题title"><a href="#" onfocus="this.blur();" onclick="return false;"><span class="PageCloseButton" title="关闭" onclick="">×</span><span class="PageTitleBg0"><span class="PageTitleBg1"><span class="PageTitleBg2">我的标题2</span></span></span></a></div>
                <div class="PageTitle" title="我的标题title"><a href="#" onfocus="this.blur();" onclick="return false;"><span class="PageCloseButton" title="关闭" onclick="">×</span><span class="PageTitleBg0"><span class="PageTitleBg1"><span class="PageTitleBg2">我的标题9</span></span></span></a></div>-->
					</div>
				</div>
			</div>
		</div>
		<div id="filesDiv">
			<div class="inner" id="ContentWindow">
				<div id="StartPage" class="inside">
					<div id="StartPageContent" style="padding: 0.5em;">
						<div id="PathBox">
							<div>
								<span>当前位置：</span><input type="text" id="FolderPath" name="FolderPath" size="60" /><input type="button" value="Go" /></div>
							<div>
								<span>操作对象：</span><input type="text" id="FilePath" name="FilePath" size="40" /><input type="button" value="Go" /></div>
						</div>
						<div id="checkedbox">
						</div>
						<div>
							<form action="" target="_blank">
							<input type="hidden" name="act" value="remotedownload" />
							<input type="text" name="url" id="RemoteDownload" value="http://" size="80" />
							<input type="submit" name="" value="下载" />
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div id="footer">
			<div id="footerInner">
				<span id="StatusBar" style="text-align: center;">页面执行时间：<%=runTime()%>
					毫秒 </span>
			</div>
		</div>
	</div>
</body>
</html>
